#!/usr/bin/env python

import checkpointutils as ck
import sys
import os
import subprocess as sb
import vm
import nodeutils as nu

############### Checkpoint test ########################
"""
list = nu.EnumVMDomIDs()

print list


for i in list:
	vms = nu.BuildVMObj(i)
	uuid = str(vms.domainCfgVars['uuid'])
	os.system('xm destroy ' + str(i))
	print 'Domain ' + str(i) + 'Destroyed'
    os.system('umount /vm/mnt/' + uuid + '/')
    print 'Unmounted'

    loopdev = str(ck.GetLoopDev(vms))

    cmd = '/sbin/losetup -d ' + loopdev
    print cmd

    p_detatch = sb.Popen('%s' %cmd, shell=True)
    p_detatch.wait()
    print 'Loop device detached'
	tmpss = ck.ListSS(uuid)
	s = tmpss[-1]
	ck.SnapshotMountCopy(loopdev,uuid,s)
	print uuid

#os.system('xm destroy ' + str(domid))
#print 'Domain Destroyed'

#os.system('umount /vm/mnt/' + uuid + '/')
#print ' unmounted'

#cmd = '/sbin/losetup -d /dev/loop0'
#p_detatch = sb.Popen('%s' %cmd, shell=True)
#p_detatch.wait()
#print 'Loop device detached'

#ck.PerformSaveSnapshot(vms)
#ck.PrintSSList('8ee1f5a3-6a96-00b1-e93b-aaf99efbe948')
#slist = ck.ListSS('8ee1f5a3-6a96-00b1-e93b-aaf99efbe948')
#s = slist[-1]
#print s.version
#ck.Migrate(vms)	
"""
ck.CleanCheckpointLogs('270611ed-2096-bfb0-ccc2-1cca54f415c4')
